package me.xue.communityhealth.service;

import me.xue.communityhealth.exception.ObjectNotFoundException;
import me.xue.communityhealth.model.DrugSupplier;
import me.xue.communityhealth.repo.DrugSupplierRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugSupplierService implements BaseService<DrugSupplier, Integer> {

    private final DrugSupplierRepository repository;

    @Autowired
    public DrugSupplierService(DrugSupplierRepository repository) {
        this.repository = repository;
    }

    @Override
    public int save(DrugSupplier drugSupplier) {
        return repository.save(drugSupplier);
    }

    @Override
    public int update(DrugSupplier drugSupplier) {
        return repository.update(drugSupplier);
    }

    public DrugSupplier findOne(Integer id) {
        DrugSupplier drugSupplier = repository.findOne(id);
        if (drugSupplier == null) {
            throw new ObjectNotFoundException();
        }
        return drugSupplier;
    }

    @Override
    public int delete(Integer which) {
        return repository.delete(which);
    }

    @Override
    public List<DrugSupplier> findAll() {
        return repository.findAll();
    }
}
